<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Sf_model extends My_Model
{
   
    public function __construct()
    {
        parent::__construct();
        $this->model_name="顺丰物流";
        $this->tablename="sf";   
    }
   
    
    public function getpage($page,$key=''){
        $where=array();
        if($key)
        {
            $search=['ordersn'=>$key,'sfordersn'=>$key,'reciver'=>$key,'re_mobile'=>$key,'remark'=>$key];
        }
        else
        {
            $search=[];
        }
        return $this->get_items_by_page($where,$page,"backend/sfexpress/record","id desc",[],$search);
    }

    
    public function getcdmap()
    {
        $map=[];
        $where = " method='F2' and sfordersn='' and orderid>0";
        $list = $this->get_items_by_where($where);
        if($list)
        {
            foreach($list as $item)
            {
                $map[$item["orderid"]]=$item["id"];
            }
        }
        return $map;
    }
    
    public function getitembyid($id)
    {
        $where=array("id"=>$id);
        return $this->get_item_by_where($where);
    }

    public function get_by_oid($orderid)
    {
        $where=array("orderid"=>$orderid);
        return $this->get_item_by_where($where);
    }

    public function getolist()
    {
        $where="orderid>0";
        return $this->get_items_by_where($where);
    }
    
    public function create($data){
        if(!isset($data["addtime"])){
            $data["addtime"]=date("Y-m-d H:i:s");
        }
        if(!isset($data["adminid"])||empty($data["adminid"])){
            $data["adminid"]=$this->adminid;
        }
        return $this->add_item($data);         
    }

    public function get_cdlist()
    {
        $where="method='F2' and sfordersn=''";
        return $this->get_items_by_where($where);
    }

    public function update($id,$data){
        if(is_array($id))
        {
            $where="id in (".implode(",",$id).")";
          
        }else{
            $where=array("id"=>$id);
        
        }
        return $this->update_item($where,$data);
    }

    public function delitem($id)
    {
        if(is_array($id))
        {
            $where="id in (".implode(",",$id).")";
        }
        else
        {
            $where=["id"=>$id];
        }
        $this->delete($where);
        return true;
    }

   
}
